package com.banciyuan.bcywebview.biz.goods.store;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.utils.universalimageloader.core.ImageLoader;
import com.banciyuan.bcywebview.utils.universalimageloader.utils.ImageOptions;

import java.util.List;

import de.greenrobot.daoexample.model.GoodsWork;


public class HotGoodsAdapter extends BaseAdapter {
    private List<GoodsWork> mGoodsWorkList;
    private Context mContext;
    private LayoutInflater mLayoutInflater;
    private ImageLoader mImageLoader;

    public HotGoodsAdapter(List<GoodsWork> goodsWorkList, Context context) {
        mGoodsWorkList = goodsWorkList;
        mContext = context;
        mLayoutInflater = LayoutInflater.from(mContext);
        mImageLoader = ImageLoader.getInstance();
    }

    @Override
    public int getCount() {
        return mGoodsWorkList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        GoodsWork goodsWork = mGoodsWorkList.get(position);
        if (null == convertView) {
            convertView = mLayoutInflater.inflate(R.layout.hotgoods_item, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        mImageLoader.displayImage(goodsWork.getCover(), viewHolder.ivGoodsCover, ImageOptions.optionsGray);
        viewHolder.tvGoodsName.setText(Html.fromHtml(goodsWork.getReal_name()));
        return convertView;
    }

    class ViewHolder {
        private ImageView ivGoodsCover;
        private TextView tvGoodsName;

        public ViewHolder(View convertView) {
            ivGoodsCover = (ImageView) convertView.findViewById(R.id.iv_goods_cover);
            tvGoodsName = (TextView) convertView.findViewById(R.id.tv_goods_name);
        }
    }
}
